package com.jasonkurtzman.adv.Level;

import java.awt.Color;
import java.awt.Graphics;
import java.util.Random;

import com.jasonkurtzman.adv.GamePanel;
import com.jasonkurtzman.adv.Tile.*;

public class Level {
	
	
	public static final int LEVEL_SIZE = 50;
	
	//public Tile worldTiles[][] = new Tile[Tile.TILE_SIZE * LEVEL_SIZE + 1][Tile.TILE_SIZE * LEVEL_SIZE + 1];
	//public Tile worldTiles[][] = new Tile[Tile.TILE_SIZE * (GamePanel.XSIZE / Tile.TILE_SIZE) + 1][Tile.TILE_SIZE * (GamePanel.YSIZE / Tile.TILE_SIZE) + 1];
	public Tile worldTiles[][] = new Tile[Tile.TILE_SIZE * (GamePanel.XSIZE / Tile.TILE_SIZE) + (Tile.TILE_SIZE * 10) + 1][Tile.TILE_SIZE * (GamePanel.YSIZE / Tile.TILE_SIZE) + (Tile.TILE_SIZE * 10) + 1];
	
	public void genLevel()
	{
		for(int x = 0; x < worldTiles.length; x += Tile.TILE_SIZE)
		{
			for(int y = 0; y < worldTiles[x].length; y += Tile.TILE_SIZE)
			{
				worldTiles[x][y] = new GrassTile(x, y);
				
				if(new Random().nextInt(25) < 2) worldTiles[x][y] = new StoneTile(x, y);
				
				if(worldTiles[x][y] == null) worldTiles[x][y] = new AirTile(x, y);
			}
		}
	}
	
	public void render(Graphics g)
	{
		g.setColor(Color.WHITE);
		g.fillRect(0, 0, GamePanel.XSIZE, GamePanel.YSIZE);
		
		for(int x = 0; x <= GamePanel.XSIZE + Tile.TILE_SIZE; x+=Tile.TILE_SIZE)
		{
			for(int y = 0; y <= GamePanel.YSIZE + Tile.TILE_SIZE; y+=Tile.TILE_SIZE)
			{
				worldTiles[x][y].render(g);
				//if(worldTiles[x][y + Tile.TILE_SIZE].getTileID() == 2) System.out.println("Stone!");
			}
		}
	}
}
